package com.hspedu.debug_.project;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author yulian174
 * @version 1.0
 */
public class Menu {
    private String name1 = "零钱通明细";
    private String name2 = "收益入账";
    private String name3 = "消费";
    private String name4 = "退   出";
    private int count;
    private double money;
    private String detail = "";
    Scanner sc = new Scanner(System.in);
    private int flag;

    public void menu() {
        flag = 1;
        do {
            prin(name1);
            prin1();
            System.out.print("请选择(1-4)：");
            int i = sc.nextInt();
            sprint(i);
        } while (flag == 1);
    }

    public void prin(String name) {
        for (int i = 0; i < 17; i++) {
            System.out.print("-");
        }
        System.out.print(name);
        for (int i = 0; i < 17; i++) {
            System.out.print("-");
        }
        System.out.println();

    }

    public void prin1() {
        String name4 = "\t\t\t 4 退   出\n";
        String name3 = "\t\t\t 3 消费\n";
        String name2 = "\t\t\t 2 收益入账\n";
        String name1 = "\n\t\t\t 1 零钱通明细\n";
        System.out.println(name1 + name2 + name3 + name4);
    }

    public String name1() {
        money = sc.nextDouble();
        count += money;
        SimpleDateFormat sdp = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        detail += "\n收款入账 +" + money + " " + sdp.format(new Date()) + " 总余额 " + count;
        return "收款入账 +" + money + " " + sdp.format(new Date()) + " 总余额 " + count;
    }

    public String name3() {
        System.out.print("消费项目：");
        String names = sc.next();
        System.out.print("消费金额：");
        money = sc.nextDouble();
        count -= money;
        SimpleDateFormat sdp = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        detail += "\n消费项目 +" + names + " 消费金额 " + money + " " + sdp.format(new Date()) + " 总余额 " + count;
        return "消费项目 +" + names + " 消费金额 " + money + " " + sdp.format(new Date()) + " 总余额 " + count;
    }

    public void sprint(int i) {
        if (i == 1) {
            prin(name1);
            System.out.println(detail);
        } else if (i == 2) {
            prin(name2);
            System.out.print("收益入账：");
            System.out.println(name1());
        } else if (i == 3) {
            prin(name3);
            System.out.println(name3());
        } else {
            prin(name4);
            System.out.println("程序已退出");
            flag = 0;
        }
    }
}
